﻿<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title></title>
    <script src="/Style/JS/Aries.Loader.js"></script>
</head>
<body style="margin-top: -4px; padding: 0">
    <div style="height: 375px">
        <table id="dg"></table>
    </div>
    <script>
        var $input = parent.AR.Global.Dialog.$target;
        var comboboxOption = {
            valueField: 'value',
            textField: 'text',
            data: [],
            width: 150,
            multiple: false,
            editable: false
        }
        var returnValue = { option: comboboxOption };
        var oName = AR.Utility.queryString("objName");
        if (oName) {
            var dg = new AR.DataGrid("_" + oName);
            dg.ToolBar.isHidden = true;
            dg.Search.BtnReset.isHidden = true;
            var multiple = $input.attr("multiple");//这个字段是JQ字段，特殊，赋值后会被变更为相同的文本
            var onlytext = $input.attr("onlytext") == "true";
            comboboxOption.editable = $input.attr("editable") == "true";
            dg.isShowCheckBox = multiple == "true" || multiple == "multiple";
            comboboxOption.multiple = dg.isShowCheckBox;
            var id = $input.attr("valueField");
            var title = $input.attr("textField");
            var options = {
                pageSize: 10,
                //fit: false,
                onLoadSuccess: function () {
                    title || (title = dg.Internal.headerData[1].field);
                    id || (id = (onlytext ? title : dg.Internal.primarykey));
                },
                onSelect: function (rowIndex, rowData) {
                    if (!dg.isShowCheckBox) {
                        var d = {};
                        d.text = rowData[title];
                        d.value = rowData[id];
                        comboboxOption.data[0] = d;
                        returnValue.text = d.text;
                        returnValue.value = d.value;
                        returnValue.data = rowData;
                        parent.AR.Global.Dialog.returnValue = returnValue;
                    }
                },
                onDblClickRow: function (rowIndex, rowData) {
                    if (!dg.isShowCheckBox) {
                        var opts = parent.AR.Global.Dialog.options;
                        opts.toolbar[0].handler();//自动触发确定按钮事件
                    }
                    else {
                        dg.datagrid("checkRow", rowIndex);
                    }
                },
                onCheck: function (rowIndex, rowData) {
                    onCheck();
                },
                onCheckAll: function (rows) {
                    onCheck();
                },
                onUncheckAll: function (rows) {
                    onCheck();
                }
            }

            try {
                var op = $input.attr("options");
                if (op) { op = eval("(" + op + ")"); }
                if (op) {
                    options = $.extend(options, op);
                }
            } catch (e) {

            }

            dg.options = options;
            dg.bind();
        }
        else { alert("dialog ： 'this objName' can't be empty!"); }
        function onCheck() {
            var rows = dg.getChecked();
            if (rows && rows.length > 0) {
                comboboxOption.data = [];
                for (var i = 0; i < rows.length; i++) {
                    var d = {};
                    d.text = rows[i][title];
                    d.value = rows[i][id];
                    comboboxOption.data.push(d);
                }
                returnValue.text = dg.getCheckIDs(title);
                returnValue.value = dg.getCheckIDs(id);
                returnValue.data = rows;
                parent.AR.Global.Dialog.returnValue = returnValue;
            }
            else {
                parent.AR.Global.Dialog.returnValue = undefined;
            }
        }
    </script>
</body>
</html>
